package com.itheima.job;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateTest03 {
    public static void main(String[] args) throws ParseException {
        String one = "2014年09/28 23时13分01秒";
        String two = "2009-02月12日 12时02分01秒";
        Method01(one, two);//2054

        Method02(one, two);

        Method03(one, two);

    }

    private static void Method03(String one, String two) {
        DateTimeFormatter onePattern = DateTimeFormatter.ofPattern("yyyy年MM/dd HH时mm分ss秒");
        DateTimeFormatter twoPattern = DateTimeFormatter.ofPattern("yyyy-MM月dd日 HH时mm分ss秒");

        LocalDateTime oneDateTime = LocalDateTime.parse(one, onePattern);
        LocalDateTime twoDateTime = LocalDateTime.parse(two, twoPattern);

        Duration duration = Duration.between(twoDateTime, oneDateTime);
        long seconds = duration.toSeconds();
        System.out.println(seconds/60/60/24);
    }

    private static void Method02(String one, String two) {
        DateTimeFormatter onePattern = DateTimeFormatter.ofPattern("yyyy年MM/dd HH时mm分ss秒");
        DateTimeFormatter twoPattern = DateTimeFormatter.ofPattern("yyyy-MM月dd日 HH时mm分ss秒");

        LocalDateTime oneDateTime = LocalDateTime.parse(one, onePattern);
        LocalDateTime twoDateTime = LocalDateTime.parse(two, twoPattern);

        //System.out.println(oneDateTime);//2014-09-28T23:13:01
        //System.out.println(twoDateTime);//2009-02-12T12:02:01

        LocalDate oneLocalDate = oneDateTime.toLocalDate();
        LocalDate twoLocalDate = twoDateTime.toLocalDate();

        //System.out.println(oneLocalDate);//2014-09-28
        //System.out.println(twoLocalDate);//2009-02-12

        Period between = Period.between(twoLocalDate, oneLocalDate);
        System.out.println(between);//P5Y7M16D
        int days = between.getDays();
        System.out.println(days);//16
    }

    private static void Method01(String one, String two) throws ParseException {
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM/dd HH时mm分ss秒");
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM月dd日 HH时mm分ss秒");
        Date oneDate = sdf1.parse(one);
        Date twoDate = sdf2.parse(two);

        long time = (oneDate.getTime() - twoDate.getTime()) / 1000 / 60 / 60 / 24;
        System.out.println(time);
    }
}
